package com.ehotting.edsta.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ehotting.eaf.core.utils.poi.ExcelUtil;
import com.ehotting.eaf.core.web.controller.BaseController;
import com.ehotting.eaf.core.web.domain.AjaxResult;
import com.ehotting.eaf.core.web.page.TableDataInfo;
import com.ehotting.edsta.common.log.annotation.Log;
import com.ehotting.edsta.common.log.enums.BusinessType;
import com.ehotting.eaf.security.annotation.PreAuthorize;
import com.ehotting.eaf.core.domain.system.api.UserLicense;
import com.ehotting.edsta.system.service.IUserLicenseService;
import io.swagger.annotations.ApiOperation;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * C端用户licenseController
 * 
 * @author edsta
 * @date 2023-03-24
 */
@RestController
@RequestMapping("/license")
public class UserLicenseController extends BaseController
{
    @Autowired
    private IUserLicenseService userLicenseService;

    /**
     * 查询C端用户license列表
     */
    @PreAuthorize(hasPermi = "system:license:list")
    @GetMapping("/list")
    public TableDataInfo list(UserLicense userLicense)
    {
        startPage();
        List<UserLicense> list = userLicenseService.selectUserLicenseList(userLicense);
        return getDataTable(list);
    }

    /**
     * 导出C端用户license列表
     */
    @PreAuthorize(hasPermi = "system:license:export")
    @Log(title = "C端用户license", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserLicense userLicense) throws IOException
    {
        List<UserLicense> list = userLicenseService.selectUserLicenseList(userLicense);
        ExcelUtil<UserLicense> util = new ExcelUtil<UserLicense>(UserLicense.class);
        util.exportExcel(response, list, "C端用户license数据");
    }

    /**
     * 获取C端用户license详细信息
     */
    @PreAuthorize(hasPermi = "system:license:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userLicenseService.selectUserLicenseById(id));
    }

    /**
     * 新增C端用户license
     */
    @PreAuthorize(hasPermi = "system:license:add")
    @Log(title = "C端用户license", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserLicense userLicense)
    {
        return toAjax(userLicenseService.insertUserLicense(userLicense));
    }

    /**
     * 修改C端用户license
     */
    @PreAuthorize(hasPermi = "system:license:edit")
    @Log(title = "C端用户license", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserLicense userLicense)
    {
        return toAjax(userLicenseService.updateUserLicense(userLicense));
    }

    /**
     * 删除C端用户license
     */
    @PreAuthorize(hasPermi = "system:license:remove")
    @Log(title = "C端用户license", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userLicenseService.deleteUserLicenseByIds(ids));
    }

    /**
     * 批量审核license
     */
    @ApiOperation("批量审核license")
    @PostMapping("/patchVerify")
    @PreAuthorize(hasPermi = "system:license:verify")
    public AjaxResult verify(Long[] ids,String status){
        return toAjax(userLicenseService.verifyUserLicenseByIds(ids,status));
    }

    /**
     * 审核license
     */
    @ApiOperation("审核license")
    @GetMapping("/verify")
//    @PreAuthorize(hasPermi = "system:license:verify")
    public AjaxResult verify(@RequestParam("id") Long id){
        return toAjax(userLicenseService.verifyUserLicenseById(id));
    }

    /**
     * 审核license
     */
    @ApiOperation("审核延期license")
    @GetMapping("/verifyExtend")
//    @PreAuthorize(hasPermi = "system:license:verify")
    public AjaxResult verifyExtend(@RequestParam("id") Long id){
        return toAjax(userLicenseService.verifyExtendUserLicenseById(id));
    }

    /**
     * 审核license
     */
    @ApiOperation("审核license")
    @GetMapping("/cancel")
//    @PreAuthorize(hasPermi = "system:license:verify")
    public AjaxResult cancel(@RequestParam("id") Long id){
        return toAjax(userLicenseService.cancelUserLicenseById(id));
    }
}
